package com.keyware.kd.task.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/** 
 * @ClassName: PropertiesUtil
 * @Description: Properties工具类
 * @author yanwj
 * @date 2016年2月26日 下午4:53:36
 * 
 */
public class PropertiesUtil {
	// Properties继承于HashMap key:value都是String类型
	private Properties prop = new Properties();

	
	
	/**
	 * 读取指定properties文件
	 * @param file
	 */
	public PropertiesUtil(String file) {
		try {
			prop.load(new FileInputStream(file));
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public PropertiesUtil(InputStream stream) {
		try {
			prop.load(stream);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int getInt(String key) {
		return Integer.parseInt(prop.getProperty(key));
	}

	public String getString(String key) {
		return prop.getProperty(key);
	}

	public double getDouble(String key) {
		return Double.parseDouble(prop.getProperty(key));
	}

	public Properties getProperties() {
		return prop;
	}

	public Properties getProp() {
		return prop;
	}

	public void setProp(Properties prop) {
		this.prop = prop;
	}
	
}